## Two auxiliary functions:zero_positions and flip

from PyM import *

# # f is assumed to be in a polynomial ring K[X]
# # and a a list or vector of elements of K 
# def zero_positions(f,a):
#     return [j for j in range(len(a)) if evaluate(f,a[j])==0]
#  
# # x is a list or vetor with entries in a ring K
# # and j  may be absent, an integer, or a list/vector
# # of integers.
# def flip(x,j=''):   
#     n = len(x)
#     y = clone(x)
#     if j == '':
#         for j in range(len(x)):
#             y[j] = 1 - y[j]
#         return y
#     if isinstance(j,int):
#         if 0<=j and j<n:
#             y[j] = 1-y[j]
#             return y
#         else: 
#             return "flip error: index out of range"
#     if isinstance(j,list):
#         for k in j:
#             if 0<=k and k<n:
#                 y[k] = 1-y[k]
#             else:
#                 return "flip error: index out of range"
#         return y
#     if isinstance(j,Vector_type):
#         return flip(x,list(j))
#     return "flip error: wrong data"

# Examples

[_,X] = polynomial_ring(Z_, 'X')

f = (X-1)*(X-2)*(X-3)

a = [0,1,7,2,9,3,11,1,2]

Z = zero_positions(f,a)
show(Z)


x = [1,1,0,0,1,0]
show(x)
y = flip(x,0)
show(y)
y = flip(x,[2,3])
show(y)
y = flip(x)
show(y)
show(flip(x,7))